package com.zh.jbet.core.entity;

import com.zh.tree.NestedUserObject;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;

@Entity
@Table(name = "GAMECONTEXT")
public class GameContext implements Game, BaseEntity, NestedUserObject, Serializable {

    private Long id;
    private Long rootId;
    private Long parentId;
    private Player owner;
    private int nestedStart;
    private int nestedEnd;
    private String name;
    private String shortName;
    private Date startTime;
    private Boolean finished;

    @Id
    @SequenceGenerator(name = "S_GAMECONTEXT", sequenceName = "S_GAMECONTEXT", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_GAMECONTEXT")
    @Override
    public Long getId() {
        return id;
    }

    protected void setId(Long id) {
        this.id = id;
    }

    @Basic
    @Override
    public Long getRootId() {
        return rootId;
    }

    @Override
    public void setRootId(Long rootId) {
        this.rootId = rootId;
    }

    @Basic
    @Override
    public Long getParentId() {
        return parentId;
    }

    @Override
    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    @ManyToOne()
    @JoinColumn(name="OWNERID")
    public Player getOwner() {
        return owner;
    }

    public void setOwner(Player owner) {
        this.owner = owner;
    }

    @Basic
    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Override
    public String getShortName() {
        return shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Basic
    @Override
    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }


    @Basic
    @Override
    public int getNestedEnd() {
        return nestedEnd;
    }

    @Override
    public void setNestedEnd(int nestedEnd) {
        this.nestedEnd = nestedEnd;
    }

    @Basic
    @Override
    public int getNestedStart() {
        return nestedStart;
    }

    @Override
    public void setNestedStart(int nestedStart) {
        this.nestedStart = nestedStart;
    }

    @Basic
    @Override
    public Boolean isFinished() {
        return finished;
    }

    public void setFinished(Boolean finished) {
        this.finished = finished;
    }

    @Transient
    public boolean isOpened() {
        return startTime != null;
    }
}
